package LatexForResults;

import java.io.BufferedWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;

import Analysis.CorrelationsClass;
import Definitions.GraphClass;
import Global.ConstantVariable;
import GraphProperties.PropertiesOfGraphClass;
import Result.MetaResultListsClass;
import Result.ResultClassListClass;
import SyntheticData.syntheticDataGeneratorClass;



public final class LatexUtilityForSyntheticDatasetsResultsClass {
	
	static int syntheticDatasetIndex=1;
	static int syntheticDatasetGeneratedWithTheSameParamatersIndex=1;
	
	public static void increaseSyntheticDatasetIndex()
	{
		syntheticDatasetIndex++;	
	}
	
	public static void increasesyntheticDatasetGeneratedWithTheSameParamatersIndex()
	{
		syntheticDatasetGeneratedWithTheSameParamatersIndex++;	
	}
	
	public static class synDescriptorTableCreatorClass
	{
		public static void printLatexSynDescriptorTableHeaderFirstPartToTheFile(BufferedWriter out)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{Synthetic Dataset Descriptors}");
				out.write("\n");
				out.write("\\begin{tabular}{|c|c|c|c|c|c|c|}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("Syn D. No  & $m_c$ (Content) & $m_l$ (Link) & $m_s$ (Shared)  & $m_h$ (Hidden)& Index & Threshold\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}

		public static void addRecordToTheSynDescTableForTheNewSyntheticDataset(syntheticDataGeneratorClass currentSyntheticDataset)
		{
			BufferedWriter out;
			
			out = currentSyntheticDataset.outForSyntehicDataDescriptorFile; 
			
			try
			{
				out.write(syntheticDatasetIndex
						+ "  & " + currentSyntheticDataset.getNumberOfContentBits() 
						+ "  & " + currentSyntheticDataset.getNumberOfLinkBits()
						+ "  & " + currentSyntheticDataset.getNumberOfSharedBits()
						+ "  & " + currentSyntheticDataset.getNumberOfHiddenBits()
						+ "  & " + currentSyntheticDataset.getDatasetNoWithTheseParameters()
						+ "  &"  + currentSyntheticDataset.getThresholdLevel()*(1.0/currentSyntheticDataset.getNumberOfLinkBits()) +"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");				
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}

		public static void printLatexSynDescTableHeaderEndPartToTheFile(BufferedWriter out)	
		{		
			try
			{
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:DataSyntheticDesc}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	/******************************************************************************************/
		
	public static class synDataSummaryResultsTableCreatorClass
	{
		public static void printLatexSynSummaryResultsTableHeaderFirstPartToTheFile(BufferedWriter out)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{Synthetic Dataset Summary Results}");
				out.write("\n");
				out.write("\\begin{tabular}{|l|");				
				for(int i=0; i<LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetSummaryResultsTableCreatorClass.calculateNumberOfColumnsForSummaryTables(); i++)
					out.write("c|");
				out.write("}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("No ");
				
				if(ConstantVariable.ExecutionParameters.isContentOnlyExecutionEnabled)
					out.write("& A.(CO) ");
				
				if(ConstantVariable.ExecutionParameters.isLinkOnlyExecutionEnabled)
					out.write("& A.(LO) ");
				
				if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)
					out.write("& A.(ICA) ");
				
				if(ConstantVariable.ExecutionParameters.isMetaClassifierExecutionEnabled)
				{
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierAverageMethodEnabled)
						out.write("& A.(AVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierMaxMethodEnabled)
						out.write("& A.(MAX) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierProductMethodEnabled)
						out.write("& A.(PRD) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMethodEnabled)
						out.write("& A.(wAVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierDegreeFilterMethodEnabled)
						out.write("& A.(DF) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMethodEnabled)
						out.write("& A.(bAVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMaxMethodEnabled)
						out.write("& A.(laMAX) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMaxMethodEnabled)
						out.write("& A.(lbMAX) ");
				}
				
				out.write("\\\\");
				out.write("\n");
				out.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

		public static void addRecordToTheSynSummaryResultsTableForTheNewSyntheticDataset(syntheticDataGeneratorClass currentSyntehicData)//ArrayList<ArrayList<ResultClass>> results)
		{
			try
			{
				BufferedWriter localOutForSyntehicDataResultsSummaryFile;
				
				localOutForSyntehicDataResultsSummaryFile = currentSyntehicData.outForSyntehicDataResultsSummaryFile;
				
				ResultClassListClass resultsListForCO = currentSyntehicData.getResultsForCO();
				ResultClassListClass resultsListForLO = currentSyntehicData.getResultsForLO();
				ResultClassListClass resultsListForICA = currentSyntehicData.getResultsForICA();
				
				ResultClassListClass  resultsListForAVE  = currentSyntehicData.getResultsForAVE();
				ResultClassListClass  resultsListForMAX  = currentSyntehicData.getResultsForMAX();
				ResultClassListClass  resultsListForPROD = currentSyntehicData.getResultsForPROD();
				ResultClassListClass  resultsListForLA   = currentSyntehicData.getResultsForLA();	
				ResultClassListClass  resultsListForDFMM   = currentSyntehicData.getResultsForDFMM();
				ResultClassListClass  resultsListForLB   = currentSyntehicData.getResultsForLB();
				ResultClassListClass  resultsListForLAMAX   = currentSyntehicData.getResultsForLAMAX();
				ResultClassListClass  resultsListForLBMAX   = currentSyntehicData.getResultsForLBMAX();

				/*
				int numberOfResultsForCO  = 0;
				int numberOfResultsForLO = 0;
				int numberOfResultsForICA = 0;

				if(resultsListForCO != null)
					numberOfResultsForCO = resultsListForCO.size();

				if(resultsListForLO != null)
					numberOfResultsForLO = resultsListForLO.size();

				if(resultsListForICA != null)
					numberOfResultsForICA = resultsListForICA.size();


				System.out.println("numberOfResultsForCO:"+numberOfResultsForCO);
				System.out.println("numberOfResultsForLO:"+numberOfResultsForLO);
				System.out.println("numberOfResultsForICA:"+numberOfResultsForICA);
				  */
				 
				NumberFormat formatterForAcc = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForSummaryAccuracies);
				
				NumberFormat formatterForErr = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForFoldAccuracies);
							
				localOutForSyntehicDataResultsSummaryFile.write(syntheticDatasetIndex 
						+ "  & " + (resultsListForCO==null ? "" : "  & " + formatterForAcc.format(resultsListForCO.calculateAverageAccuracyObtained()) + " $\\pm$ " + formatterForErr.format(resultsListForCO.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLO==null ? "" : "  & " + formatterForAcc.format(resultsListForLO.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForLO.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForICA==null ? "" : "  & " + formatterForAcc.format(resultsListForICA.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForICA.findErrorBarOfAccuracyResults())) 
						+ "  & " + (resultsListForAVE==null ? "" : "  & " + formatterForAcc.format(resultsListForAVE.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForAVE.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForMAX==null ? "" : "  & " + formatterForAcc.format(resultsListForMAX.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForMAX.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForPROD==null ? "" : "  & " + formatterForAcc.format(resultsListForPROD.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForPROD.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLA==null ? "" : "  & " + formatterForAcc.format(resultsListForLA.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForLA.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForDFMM==null ? "" : "  & " + formatterForAcc.format(resultsListForDFMM.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForDFMM.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLB==null ? "" : "  & " + formatterForAcc.format(resultsListForLB.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForLB.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLAMAX==null ? "" : "  & " + formatterForAcc.format(resultsListForLAMAX.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForLAMAX.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLBMAX==null ? "" : "  & " + formatterForAcc.format(resultsListForLBMAX.calculateAverageAccuracyObtained())+ " $\\pm$ " + formatterForErr.format(resultsListForLBMAX.findErrorBarOfAccuracyResults()))
						+"\\\\");

				localOutForSyntehicDataResultsSummaryFile.write("\n");
				localOutForSyntehicDataResultsSummaryFile.write("\\hline");
				localOutForSyntehicDataResultsSummaryFile.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

		public static void printLatexSynResultsTableHeaderEndPartToTheFile(BufferedWriter out)	
		{		
			try
			{
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:SyntheticDataSummaryResults}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	/******************************************************************************************/

	
	public static class synDataFoldsResultsTableCreatorClass
	{
	
		public static void printLatexSynFoldsResultsTableHeaderFirstPartToTheFile(BufferedWriter out)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{Synthetic Dataset Folds Results}");
				out.write("\n");
				out.write("\\begin{tabular}{|l|");				
				for(int i=0; i<ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_CONTENT_ONLY; i++)
					out.write("c|");
				out.write("}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("Syn D. No");
				for(int i=0; i<ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_CONTENT_ONLY; i++)
					out.write("& Ac.("+i+")");
				out.write("\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}

		public static void addRecordToTheSynFoldsResultsTableForTheNewSyntheticDataset(syntheticDataGeneratorClass currentSyntehicData)//ArrayList<ArrayList<ResultClass>> results)
		{
			try
			{
				BufferedWriter localOutForSyntehicDataFoldsResultsFile;

				localOutForSyntehicDataFoldsResultsFile = currentSyntehicData.outForSyntehicDataFoldsResultsFile;
				
				ResultClassListClass resultsListForCO = currentSyntehicData.getResultsForCO();
				ResultClassListClass resultsListForLO = currentSyntehicData.getResultsForLO();
				ResultClassListClass resultsListForICA = currentSyntehicData.getResultsForICA();
				
				ResultClassListClass  resultsListForAVE  = currentSyntehicData.getResultsForAVE();
				ResultClassListClass  resultsListForMAX  = currentSyntehicData.getResultsForMAX();
				ResultClassListClass  resultsListForPROD = currentSyntehicData.getResultsForPROD();
				ResultClassListClass  resultsListForLA   = currentSyntehicData.getResultsForLA();
				ResultClassListClass  resultsListForDFMM   = currentSyntehicData.getResultsForDFMM();
				ResultClassListClass  resultsListForLB   = currentSyntehicData.getResultsForLB();
				
				ResultClassListClass  resultsListForLAMAX   = currentSyntehicData.getResultsForLAMAX();
				ResultClassListClass  resultsListForLBMAX   = currentSyntehicData.getResultsForLBMAX();

				int numberOfResultsForCO  = 0;
				int numberOfResultsForLO = 0;
				int numberOfResultsForICA = 0;
				
				int numberOfResultsForAVE  = 0;
				int numberOfResultsForMAX = 0;
				int numberOfResultsForPRD = 0;
				int numberOfResultsForLA = 0;
				int numberOfResultsForDFMM = 0;
				int numberOfResultsForLB = 0;
				int numberOfResultsForLAMAX = 0;
				int numberOfResultsForLBMAX = 0;
				

				if(resultsListForCO != null)
					numberOfResultsForCO = resultsListForCO.size();

				if(resultsListForLO != null)
					numberOfResultsForLO = resultsListForLO.size();

				if(resultsListForICA != null)
					numberOfResultsForICA = resultsListForICA.size();
				
				if(resultsListForAVE != null)
					numberOfResultsForAVE = resultsListForAVE.size();
				
				if(resultsListForMAX != null)
					numberOfResultsForMAX = resultsListForMAX.size();
				
				if(resultsListForPROD != null)
					numberOfResultsForPRD = resultsListForPROD.size();
				
				if(resultsListForLA != null)
					numberOfResultsForLA = resultsListForLA.size();
				
				if(resultsListForDFMM != null)
					numberOfResultsForDFMM = resultsListForDFMM.size();

				if(resultsListForLB != null)
					numberOfResultsForLB = resultsListForLB.size();
				
				if(resultsListForLAMAX != null)
					numberOfResultsForLAMAX = resultsListForLAMAX.size();
				
				if(resultsListForLBMAX != null)
					numberOfResultsForLBMAX = resultsListForLBMAX.size();
		
				System.out.println("numberOfResultsForCO:"+numberOfResultsForCO);
				System.out.println("numberOfResultsForLO:"+numberOfResultsForLO);
				System.out.println("numberOfResultsForICA:"+numberOfResultsForICA);
				System.out.println("numberOfResultsForAVE:"+numberOfResultsForAVE);
				System.out.println("numberOfResultsForMAX:"+numberOfResultsForMAX);
				System.out.println("numberOfResultsForPROD:"+numberOfResultsForPRD);
				System.out.println("numberOfResultsForLA:"+numberOfResultsForLA);
				System.out.println("numberOfResultsForDFMM:"+numberOfResultsForDFMM);
				System.out.println("numberOfResultsForLB:"+numberOfResultsForLB);
				System.out.println("numberOfResultsForLAMAX:"+numberOfResultsForLAMAX);
				System.out.println("numberOfResultsForLBMAX:"+numberOfResultsForLBMAX);
				
				if(currentSyntehicData.getResultsForCO()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, currentSyntehicData.getResultsForCO(), "CO");
				
				if(currentSyntehicData.getResultsForLO()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, currentSyntehicData.getResultsForLO(), "LO");
				
				if(currentSyntehicData.getResultsForICA()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, currentSyntehicData.getResultsForICA(), "ICA");
				
				if(currentSyntehicData.getResultsForAVE()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForAVE, "AVE");
				
				if(currentSyntehicData.getResultsForMAX()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForMAX, "MAX");
				
				if(currentSyntehicData.getResultsForPROD()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForPROD, "PROD");
				
				if(currentSyntehicData.getResultsForLA()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForLA, "wAVE");
				
				if(currentSyntehicData.getResultsForDFMM()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForDFMM, "DFMM");
				
				if(currentSyntehicData.getResultsForLB()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForLB, "bAVE");
				
				if(currentSyntehicData.getResultsForLAMAX()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForLAMAX, "LAMAX");
				
				if(currentSyntehicData.getResultsForLBMAX()!=null)
					writeFoldResultToTheSynFoldsResultsTable(localOutForSyntehicDataFoldsResultsFile, resultsListForLBMAX, "LBMAX");
				
				/*
				ResultClassListClass resultsList=currentSyntehicData.getResultsForCO();
				
				String algorithmName="CO";
				String RowHeader = syntheticDatasetIndex +"-"+algorithmName;
				
				localOutForSyntehicDataFoldsResultsFile.write(RowHeader + "  & ");
				
				for(int i=0; i<resultsList.size(); i++)
				{					
					localOutForSyntehicDataFoldsResultsFile.write(Double.toString(resultsListForCO.get(i).getEvaluationResultOfWeka().pctCorrect()));
					if(i!=resultsList.size()-1)
						localOutForSyntehicDataFoldsResultsFile.write("  & "); 
						
				}
				
				localOutForSyntehicDataFoldsResultsFile.write("\\\\");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
				localOutForSyntehicDataFoldsResultsFile.write("\\hline");
				localOutForSyntehicDataFoldsResultsFile.write("\n");*/
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		static void writeFoldResultToTheSynFoldsResultsTable(BufferedWriter localOutForSyntehicDataFoldsResultsFile, ResultClassListClass resultsList, String algorithmName)
		{			
			String RowHeader = syntheticDatasetIndex +"-"+algorithmName;
			
			try
			{	
				NumberFormat formatter = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForFoldAccuracies);
				
				/*
				localOutForSyntehicDataFoldsResultsFile.write(RowHeader + "  & ");

				for(int i=0; i<resultsList.size(); i++)
				{					
					localOutForSyntehicDataFoldsResultsFile.write(formatter.format(resultsList.get(i).getEvaluationResultOfWeka().pctCorrect()));
					if(i!=resultsList.size()-1)
						localOutForSyntehicDataFoldsResultsFile.write("  & "); 

				}			
				localOutForSyntehicDataFoldsResultsFile.write("\\\\");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
				localOutForSyntehicDataFoldsResultsFile.write("\\hline");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
				*/
				
				//TODO AS EKLEME
				localOutForSyntehicDataFoldsResultsFile.write(RowHeader + "  & ");

				for(int i=0; i<resultsList.size(); i++)
				{					
					localOutForSyntehicDataFoldsResultsFile.write(formatter.format(resultsList.get(i).getEvaluationResult().getMeasures().getAccuracy()));
					if(i!=resultsList.size()-1)
						localOutForSyntehicDataFoldsResultsFile.write("  & "); 

				}			
				localOutForSyntehicDataFoldsResultsFile.write("\\\\");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
				localOutForSyntehicDataFoldsResultsFile.write("\\hline");
				localOutForSyntehicDataFoldsResultsFile.write("\n");

			}
			catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}			
		}

		static void writeFoldResultKadriyeToTheSynFoldsResultsTable(BufferedWriter localOutForSyntehicDataFoldsResultsFile, ResultClassListClass resultsList, String algorithmName)
		{			
			String RowHeader = syntheticDatasetIndex +"-"+algorithmName;
			
			try
			{	
				NumberFormat formatter = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForFoldAccuracies);
				
				localOutForSyntehicDataFoldsResultsFile.write(RowHeader + "  & ");

				for(int i=0; i<resultsList.size(); i++)
				{					
					localOutForSyntehicDataFoldsResultsFile.write(formatter.format(resultsList.get(i).getEvaluationResultOfWeka().pctCorrect()));
					if(i!=resultsList.size()-1)
						localOutForSyntehicDataFoldsResultsFile.write("  & "); 

				}			
				localOutForSyntehicDataFoldsResultsFile.write("\\\\");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
				localOutForSyntehicDataFoldsResultsFile.write("\\hline");
				localOutForSyntehicDataFoldsResultsFile.write("\n");
			}
			catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}			
		}
		
		public static void printLatexSynFoldsResultsTableHeaderEndPartToTheFile(BufferedWriter out)	
		{		
			try
			{
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:SyntheticDataFoldsResults}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	/******************************************************************************************/
	
	public static class synDataSummaryMetaResultsTableCreatorClass
	{
		public static void printLatexSynMetaResultsTableHeaderFirstPartToTheFile(BufferedWriter out)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{Synthetic Datasets Meta Accuracy Results}");
				out.write("\n");
				out.write("\\begin{tabular}{|l|");				
				for(int i=0; i<LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetSummaryResultsTableCreatorClass.calculateNumberOfColumnsForSummaryTables(); i++)
					out.write("c|");
				out.write("}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("No ");
				
				if(ConstantVariable.ExecutionParameters.isContentOnlyExecutionEnabled)
					out.write("& A.(CO) ");
				
				if(ConstantVariable.ExecutionParameters.isLinkOnlyExecutionEnabled)
					out.write("& A.(LO) ");
				
				if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)
					out.write("& A.(ICA) ");
				
				if(ConstantVariable.ExecutionParameters.isMetaClassifierExecutionEnabled)
				{
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierAverageMethodEnabled)
						out.write("& A.(AVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierMaxMethodEnabled)
						out.write("& A.(MAX) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierProductMethodEnabled)
						out.write("& A.(PRD) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMethodEnabled)
						out.write("& A.(wAVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierDegreeFilterMethodEnabled)
						out.write("& A.(DF) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMethodEnabled)
						out.write("& A.(bAVE) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMaxMethodEnabled)
						out.write("& A.(laMAX) ");
					
					if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMaxMethodEnabled)
						out.write("& A.(lbMAX) ");
				}
				
				out.write("\\\\");
				out.write("\n");
								
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

		public static void addRecordToTheSynMetaResultsTableForTheSyntheticDatasetsGeneratedWithTheSameParameters()
		{
			try
			{
				BufferedWriter localOutForSyntehicDataResultsSummaryFile;
				
				localOutForSyntehicDataResultsSummaryFile = syntheticDataGeneratorClass.outForSyntehicDataMetaResultsSummaryFile;
				
				MetaResultListsClass currentMetaResults =  syntheticDataGeneratorClass.getMetaResultsList();
				
				NumberFormat formatterForAcc = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForMetaSummaryAccuracies);
				
				NumberFormat formatterForErr = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForMetaSummaryErr);
				
				formatterForErr.setMinimumFractionDigits(2);
				formatterForErr.setMaximumFractionDigits(4);
				
				
				//String debugstr= formatterForAcc.format(currentMetaResults.findErrorBarOfAccuracyResultsForCO());
				
				//System.out.println("debugstr:"+debugstr+",debugstr1"+currentMetaResults.findErrorBarOfAccuracyResultsForCO());
				//System.exit(0);
							
				localOutForSyntehicDataResultsSummaryFile.write(syntheticDatasetGeneratedWithTheSameParamatersIndex 
						+ (currentMetaResults.getResultsListForCOOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForCO()) + " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForCO()))
						+ (currentMetaResults.getResultsListForLOOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForLO())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForLO()))
						+ (currentMetaResults.getResultsListForICAOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForICA())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForICA())) 
						+ (currentMetaResults.getResultsListForAVEOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForAVE())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForAVE()))
						+ (currentMetaResults.getResultsListForMAXOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForMAX())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForMAX()))
						+ (currentMetaResults.getResultsListForPRDOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForPRD())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForPRD()))
						+ (currentMetaResults.getResultsListForwAVEOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForwAVE())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForwAVE()))						
						+ (currentMetaResults.getResultsListForCNwAVEOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForCNwAVE())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForCNwAVE()))
						+ (currentMetaResults.getResultsListForbAVEOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForbAVE())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForbAVE()))
						+ (currentMetaResults.getResultsListForlaMAXOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForlaMAX())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForlaMAX()))
						+ (currentMetaResults.getResultsListForlbMAXOfTheDatasetsGeneratedWithTheSameParameters().size()==0 ? "" : "  & " + formatterForAcc.format(currentMetaResults.calculateAverageAccuracyObtainedForlbMAX())+ " $\\pm$ " + formatterForErr.format(currentMetaResults.findErrorBarOfAccuracyResultsForlbMAX()))
						+ "\\\\");
				
				localOutForSyntehicDataResultsSummaryFile.write("\n");
				localOutForSyntehicDataResultsSummaryFile.write("\\hline");
				localOutForSyntehicDataResultsSummaryFile.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

		public static void printLatexSynMetaResultsTableHeaderEndPartToTheFile(BufferedWriter out)	
		{		
			try
			{
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:SyntheticDataMetaAccuracyResults}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	
	/**************************************Synthetic Graph Props-Corrlelations Acc Results****************************************************/
	public static class SyntheticDatasetExtendedResultsTableCreatorClass
	{
	
		public static void printLatexSyntheticDatasetExtendedResultsTableHeaderFirstPartToTheFile(BufferedWriter out)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{");				
				out.write("Synthetic Datasets Extended Results}");
				out.write("\n");
				out.write("\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("D. No & avg-kCO & avg-cCO & avg-hCO & avg-alphaCO & avg-accCO & avg-kLO & avg-cLO & avg-hLO & avg-alphaLO & avg-accLO & k(CO)-c(CO) & k(CO)-h(CO) & k(CO)-a(CO) & k(CO)-A(CO) & k(CO)-k(LO) & k(CO)-c(LO) & k(CO)-h(LO) & k(CO)-a(LO)& k(CO)-A(LO) & c(CO)-h(CO) & c(CO)-a(CO) & c(CO)-A(CO) & c(CO)-k(LO) & c(CO)-c(LO) & c(CO)-h(LO) & c(CO)-a(LO) & c(CO)-A(LO) & h(CO)-a(CO) & h(CO)-A(CO) & h(CO)-k(LO) & h(CO)-c(LO) & h(CO)-h(LO) & h(CO)-a(LO) & h(CO)-A(LO) & a(CO)-A(CO) & a(CO)-k(LO) & a(CO)-c(LO) & a(CO)-h(LO) & a(CO)-a(LO) & a(CO)-A(LO) & A(CO)-k(LO) & A(CO)-c(LO) & A(CO)-h(LO) & A(CO)-a(LO) & A(CO)-A(LO) & k(LO)-c(LO) & k(LO)-h(LO) & k(LO)-a(LO) & k(LO)-A(LO) & c(LO)-h(LO) & c(LO)-a(LO) & c(LO)-A(LO) & h(LO)-a(LO) & h(LO)-A(LO) & a(LO)-A(LO) & Acc(CO) & Acc(LO) & Acc(ICA)\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
		
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}

		public static void addRecordToTheSyntheticDatasetExtendedResultsTable(BufferedWriter localOutForSyntheticDatasetExtendedResultsFile, ArrayList<ResultClassListClass> resultsList, GraphClass graph, CorrelationsClass correlations)
		{
			try
			{
				PropertiesOfGraphClass linkProperties = graph.getPropertiesOfTheGraphWithRespectToEdgeType().get(ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE);
				PropertiesOfGraphClass contentProperties = graph.getPropertiesOfTheGraphWithRespectToEdgeType().get(ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH);;
				
				
				
				ResultClassListClass resultsListForCO = resultsList.get(0);
				ResultClassListClass resultsListForLO = resultsList.get(1);
				ResultClassListClass resultsListForICA = resultsList.get(2);
				 
				NumberFormat formatter = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForErrorBars);
			
				localOutForSyntheticDatasetExtendedResultsFile.write(syntheticDatasetIndex
						+ " & " + (contentProperties.degreeDistributionRelatedProps==null 		? "-" :formatter.format(contentProperties.degreeDistributionRelatedProps.getAverageDegreeOfNodes()))
						+ " & " + (contentProperties.clusteringCoefficientRelatedProps==null 	? "-" :formatter.format(contentProperties.clusteringCoefficientRelatedProps.getClusteringCoefficientOfTheGraph()))
						+ " & " + (contentProperties.homophilyRelatedProps==null 				? "-" :formatter.format(contentProperties.homophilyRelatedProps.getHomophilyOfTheGraph()))
						+ " & " + (contentProperties.localAlphaRelatedProps==null 				? "-" :formatter.format(contentProperties.localAlphaRelatedProps.getLocalAlphaOfTheGraph()))
						+ " & " + (contentProperties.accuracyRelatedProps==null 				? "-" :formatter.format(contentProperties.accuracyRelatedProps.getAccuracyOfTheGraph()))
						
						+ " & " + (linkProperties.degreeDistributionRelatedProps==null 			? "-" :formatter.format(linkProperties.degreeDistributionRelatedProps.getAverageDegreeOfNodes()))
						+ " & " + (linkProperties.clusteringCoefficientRelatedProps==null 		? "-" :formatter.format(linkProperties.clusteringCoefficientRelatedProps.getClusteringCoefficientOfTheGraph()))
						+ " & " + (linkProperties.homophilyRelatedProps==null 					? "-" :formatter.format(linkProperties.homophilyRelatedProps.getHomophilyOfTheGraph()))
						+ " & " + (linkProperties.localAlphaRelatedProps==null 					? "-" :formatter.format(linkProperties.localAlphaRelatedProps.getLocalAlphaOfTheGraph()))
						+ " & " + (linkProperties.accuracyRelatedProps==null 					? "-" :formatter.format(linkProperties.accuracyRelatedProps.getAccuracyOfTheGraph()))
						
						+ " & " + formatter.format(correlations.getCor_kCO_cCO())+ " & "+ formatter.format(correlations.getCor_kCO_hCO())+ " & "+ formatter.format(correlations.getCor_kCO_alphaCO())
						+ " & " + formatter.format(correlations.getCor_kCO_accuracyCO()) + "& " + formatter.format(correlations.getCor_kCO_kLO())+ "& " + formatter.format(correlations.getCor_kCO_cLO())
						+ " & " + formatter.format(correlations.getCor_kCO_hLO())+ "& " + formatter.format(correlations.getCor_kCO_alphaLO())+ "& " + formatter.format(correlations.getCor_kCO_accuracyLO())
						+ " & " + formatter.format(correlations.getCor_cCO_hCO())+ "& "+ formatter.format(correlations.getCor_cCO_alphaCO())+ "& "+ formatter.format(correlations.getCor_kCO_accuracyCO())
						+ " & " + formatter.format(correlations.getCor_cCO_kLO())+ "& " + formatter.format(correlations.getCor_cCO_cLO())+ "& " + formatter.format(correlations.getCor_cCO_hLO())
						+ " & " + formatter.format(correlations.getCor_cCO_alphaLO()) + "& " + formatter.format(correlations.getCor_cCO_accuracyLO()) + "& " + formatter.format(correlations.getCor_hCO_alphaCO())
						+ " & " + formatter.format(correlations.getCor_hCO_accuracyCO())+ "& " + formatter.format(correlations.getCor_hCO_kLO())+ "& " + formatter.format(correlations.getCor_hCO_cLO())
						+ " & " + formatter.format(correlations.getCor_hCO_hLO())+ "& " + formatter.format(correlations.getCor_hCO_alphaLO())+ "& " + formatter.format(correlations.getCor_hCO_accuracyLO())
						+ " & " + formatter.format(correlations.getCor_alphaCO_accuracyCO())+ "& " +formatter.format(correlations.getCor_alphaCO_kLO())+ "& " + formatter.format(correlations.getCor_alphaCO_cLO())
						+ " & " + formatter.format(correlations.getCor_alphaCO_hLO())+ "& " + formatter.format(correlations.getCor_alphaCO_alphaLO())+ "& " + formatter.format(correlations.getCor_alphaCO_accuracyLO()) 
						+ " & " + formatter.format(correlations.getCor_accuracyCO_kLO())+ "& " + formatter.format(correlations.getCor_accuracyCO_cLO())+ "& " + formatter.format(correlations.getCor_accuracyCO_hLO())
						+ " & " + formatter.format(correlations.getCor_accuracyCO_alphaLO())+ "& " + formatter.format(correlations.getCor_accuracyCO_accuracyLO())+"& " + formatter.format(correlations.getCor_kLO_cLO())
						+ " & " + formatter.format(correlations.getCor_kLO_hLO())+ "& " + formatter.format(correlations.getCor_kLO_alphaLO())+ "& " + formatter.format(correlations.getCor_kLO_accuracyLO())
						+ " & " + formatter.format(correlations.getCor_cLO_hLO())+ "& " + formatter.format(correlations.getCor_cLO_alphaLO())+ "& " + formatter.format(correlations.getCor_cLO_accuracyLO())
						+ " & " + formatter.format(correlations.getCor_hLO_alphaLO())+ "& " + formatter.format(correlations.getCor_hLO_accuracyLO()) + formatter.format(correlations.getCor_alphaLO_accuracyLO())
				
						+ "  & " + (resultsListForCO==null ? "-" :resultsListForCO.calculateAverageAccuracyObtained() + " $\\pm$ " + formatter.format(resultsListForCO.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForLO==null ? "-" : resultsListForLO.calculateAverageAccuracyObtained()+ " $\\pm$ " + formatter.format(resultsListForLO.findErrorBarOfAccuracyResults()))
						+ "  & " + (resultsListForICA==null ? "-" :resultsListForICA.calculateAverageAccuracyObtained()+ " $\\pm$ " + formatter.format(resultsListForICA.findErrorBarOfAccuracyResults())) 
						+"\\\\");
				localOutForSyntheticDatasetExtendedResultsFile.write("\n");
				localOutForSyntheticDatasetExtendedResultsFile.write("\\hline");
				localOutForSyntheticDatasetExtendedResultsFile.write("\n");
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

		public static void printLatexSyntheticDatasetExtendedResultsTableHeaderEndPartToTheFile(BufferedWriter out)	
		{		
			try
			{
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:");				
				out.write("SynDatasetsExtendedResults}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}

}
